# load data

iat_data <- read_rds("./data_clean/rep_file_iat_data.RDS")


##
## descriptive stats
##


# generate Figure B.3
# Calculate and plot AUC for explicit and implicit bias measures
mean_plot_data <-
  iat_data %>%
  dplyr::select(IAT, explicit, city, ethnicity) %>%
  rename("implicit" = IAT, "explicit" = explicit) %>%
  gather(key = "question", value = "response", -city, -ethnicity) %>%
  group_by(ethnicity, city, question) %>%
  summarise(mean_response = mean(response, na.rm = TRUE)) %>%
  ungroup()

dens_plot_data <-
  iat_data %>%
  dplyr::select(IAT, explicit, city, ethnicity) %>%
  rename("implicit" = IAT, "explicit" = explicit) %>%
  gather(key = "question", value = "response", -city, -ethnicity)

my_den <- function(x){
  my_den <- density(x, na.rm = TRUE)
  my_den_x <- my_den$x
  my_den_y = my_den$y
  return(data.frame(my_den_x, my_den_y))
}

qdens <- dens_plot_data %>%
  group_by(city, ethnicity, question) %>%
  do(my_den(.$response))

auc_russia <-
  qdens %>%
  do(data.frame(auc = integrate.xy(x= .$my_den_x, fx= .$my_den_y, a=0)))

auc_russia <-
  auc_russia %>%
  mutate(y = ifelse(question == "explicit", .4, .7))

auc_russia$x <- 1

auc_russia$x <- 1.25

ggplot(dens_plot_data, aes(x = response, color = question)) +
  geom_density() +
  geom_vline(data = mean_plot_data,
             aes(xintercept = mean_response, color = question)) +
  facet_grid(city~ethnicity) +
  geom_text(data = auc_russia, aes(x = x, y = y,
                                   label = paste("auc = ", round(auc, 2)),
                                   color = question)) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "gray") +
  theme_tufte() +
  theme(legend.position = "bottom")

ggsave(filename = "./plots/city_ethnic_question_density.pdf", 
       width = 9, height = 7)

# generates Table 1 summary_stats.tex
descriptives <-
  iat_data %>%
  group_by(ethnicity) %>%
  summarise_at(vars(explicit, IAT), 
               funs(mean(., na.rm = TRUE), 
                    sd(., na.rm = TRUE),
                    min(., na.rm = TRUE),
                    max(., na.rm = TRUE),
                    # round(t.test(.)$p.value, 2)#,
                    n()
               )) %>%
  mutate(IAT = as.character(round(IAT_mean, 2)),
         IAT = str_c(IAT, c("*", "*", "*", "")),
         explicit = as.character(round(explicit_mean, 2)),
         explicit = str_c(explicit, c("*", "*", "*", ""))) %>%
  dplyr::select(-IAT_mean, -explicit_mean)

descriptives <-
  descriptives[, c(1, 11, 2, 4, 6, 8, 10, 3, 5, 7, 9)]

descriptives_total <-
  iat_data %>%
  summarise_at(vars(explicit, IAT), 
               funs(mean(., na.rm = TRUE), 
                    sd(., na.rm = TRUE),
                    min(., na.rm = TRUE),
                    max(., na.rm = TRUE),
                    # round(t.test(.)$p.value, 2),
                    n = sum(!is.na(.))
               )) %>%
  mutate(ethnicity = "All groups")

descriptives_total <- descriptives_total[,  c(11, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10)]

colnames(descriptives_total)[2] <- "explicit"
colnames(descriptives_total)[7] <- "IAT"

descriptives_total <-
  descriptives_total %>%
  mutate(explicit = as.character(str_c(explicit, "*")),
         IAT = as.character(str_c(round(IAT, 2), "*")))

descriptives <- bind_rows(descriptives,
                          descriptives_total)

colnames(descriptives) <- c("ethnicity", "mean", "SD", "min", "max", "n", "mean", "SD", "min", "max", "n")

addtorow <- list()
addtorow$pos <- list(-1)
addtorow$command <- paste0(paste0('& \\multicolumn{5}{c}{',c('Explicit (Ukr - Rus)','Implicit (Ukr - Rus)'), '}', collapse=''), '\\\\')

print(xtable(descriptives,
             caption = "Summary statistics of explicit and implicit preferences by ethnicity, with values greater than zero indicating pro-Ukraine bias. Means of the explicit measure are of the full range of possible values (i.e., integers in [-6, 6]), while the means of the implicit measure are calculated from the d-score units (i.e., real values in [-1.15, 1.64]). * indicates mean is distinct from 0 with 95\\% confidence.",
             label = "tbl:sum_stats", digits = 2),
      booktabs = TRUE,
      hline.after = c(-1,0,4),
      table.placement = "h",
      include.rownames = FALSE,
      timestamp = NULL,
      comment = FALSE,
      add.to.row=addtorow,
      file = "./tables/summary_stats.tex")

# generate Table B.1
eth_count <- 
  as.data.frame.matrix(table(iat_data$xm_bias_factor,iat_data$ethnicity)) %>% 
  rownames_to_column('category') %>%
  mutate(row_total = `Ukrainian only`+ `Russian only`+ `Ukr and Rus` + `other`,
         category = recode_factor(category, `Pro Russia SDB` = "Pro Rus. Dissoc.",
                                  `Pro Ukraine SDB` = "Pro Ukr. Dissoc." )) %>%
  arrange(desc(row_total))

eth_count_pct <-
  eth_count %>%
  mutate_at(vars(`Ukrainian only`,`other`, `Ukr and Rus`,`Russian only`),
            function(x) round(100*x/sum(x), 0))

df <-
  eth_count_pct %>%
  left_join(eth_count, by = "category") %>%
  dplyr::select(-row_total.x) %>%
  dplyr::select(c(1,6,2,7, 3,8,4,9,5, 10)) %>%
  adorn_totals("row")

names(df) <- c("category", rep(c('n','\\%'),times = 4), "Row Total")

kable(df, format = "latex", booktabs = TRUE, digits = 2,
      caption="\\label{tbl:ethnicity_means_2}
      Majorities of each of the four ethnic identity categories
      expressed an implicit and explicit preference for Ukraine (‘Pro Ukraine’) or
      an implicit preference for Ukraine but an explicit preference for Russia (`Pro Russia disassociation').
      Those respondents who expressed a neutral explicit attitude (they evaluated Russia and Ukraine the same) are coded as dissociating."
) %>%
  add_header_above(c(" ", "Ukrainian only" =2, "Other" =2, "Ukr and Rus" = 2, "Russian only" =2, "")) %>%
  row_spec(5, bold = TRUE) %>%
  cat(., file = "./tables/ethnicity_pct_by_quadrant2.tex")

# generate Table B.2

city_count <- 
  as.data.frame.matrix(table(iat_data$xm_bias_factor,iat_data$city)) %>% 
  rownames_to_column('category') %>%
  mutate(row_total = `Kyiv`+ `Kherson`+ `Odesa` + `Kharkiv`,
         category = recode_factor(category, `Pro Russia SDB` = "Pro Rus. Dissoc.",
                                  `Pro Ukraine SDB` = "Pro Ukr. Dissoc." )) %>%
  arrange(desc(row_total))

city_count_pct <-
  city_count %>%
  mutate_at(vars(`Kyiv`, `Kherson`, `Odesa`, `Kharkiv`),
            function(x) round(100*x/sum(x), 0))

df_city <-
  city_count_pct %>%
  left_join(city_count, by = "category") %>%
  dplyr::select(-row_total.x) %>%
  dplyr::select(c(1,6,2,7, 3,8,4,9,5, 10)) %>%
  adorn_totals("row")

names(df_city) <- c("category", rep(c('n','\\%'),times = 4), "Row Total")

kable(df_city, format = "latex", booktabs = TRUE, digits = 2,
      caption="\\label{tbl:city_means_2} 
      Majorities in each of the four cities
      expressed an implicit and explicit preference for Ukraine (‘Pro Ukraine’) or
      an implicit preference for Ukraine but an explicit preference for Russia (`Pro Russia disassociation').
      Those respondents who expressed a neutral explicit attitude (they evaluated Russia and Ukraine the same) are coded as dissociating.") %>%
  add_header_above(c(" ", "Kyiv" =2, "Kherson" =2, "Odesa" = 2, "Kharkiv" =2, "")) %>%
  row_spec(5, bold = TRUE) %>%
  cat(., file = "./tables/city_pct_by_quadrant2.tex")
# 

# Table B.3
# explicit and implicit summary stats by city

descriptives <-
  iat_data %>%
  group_by(city) %>%
  summarise_at(vars(explicit, IAT), 
               funs(mean(., na.rm = TRUE), 
                    sd(., na.rm = TRUE),
                    min(., na.rm = TRUE),
                    max(., na.rm = TRUE),
                    n()
               )) %>%
  mutate(IAT = as.character(round(IAT_mean, 2)),
         explicit = as.character(round(explicit_mean, 2))) %>%
  dplyr::select(-IAT_mean, -explicit_mean)

descriptives <-
  descriptives[, c(1, 11, 2, 4, 6, 8, 10, 3, 5, 7, 9)]

descriptives_total <-
  iat_data %>%
  summarise_at(vars(explicit, IAT), 
               funs(mean(., na.rm = TRUE), 
                    sd(., na.rm = TRUE),
                    min(., na.rm = TRUE),
                    max(., na.rm = TRUE),
                    n = sum(!is.na(.))
               )) %>%
  mutate(city = "All cities")

descriptives_total <- descriptives_total[,  c(11, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10)]

colnames(descriptives_total)[2] <- "explicit"
colnames(descriptives_total)[7] <- "IAT"

descriptives_total <-
  descriptives_total %>%
  mutate(explicit = as.character(explicit),
         IAT = as.character(str_c(round(IAT, 2))))

descriptives <- bind_rows(descriptives,
                          descriptives_total)

colnames(descriptives) <- c("city", "mean", "SD", "min", "max", "n", "mean", "SD", "min", "max", "n")

addtorow <- list()
addtorow$pos <- list(-1)
addtorow$command <- paste0(paste0('& \\multicolumn{5}{c}{',c('Explicit (Ukr - Rus)','Implicit (Ukr - Rus)'), '}', collapse=''), '\\\\')

kable(descriptives, format = "latex", booktabs = TRUE, digits = 2,
      caption="\\label{tbl:sum_stats_city}
             Summary statistics of explicit and implicit preferences by city, with values greater than zero indicating pro-Ukraine bias.") %>%
  add_header_above(c(" ", "Explicit" =5, "Implicit" =5)) %>%
  row_spec(5, bold = TRUE) %>%
  cat(., file = "./tables/summary_stats_city.tex")


# LANGUAGE BY CITY
# generate Table B.4

lang_city_count <-
  as.data.frame.matrix(table(iat_data$home_language, iat_data$city)) %>% 
  rownames_to_column('category') %>%
  mutate(row_total = `Kyiv`+ `Kherson`+ `Odesa` + `Kharkiv`) %>%
  arrange(desc(row_total))

lang_city_count_pct <-
  lang_city_count %>%
  mutate_at(vars(`Kyiv`, `Kherson`, `Odesa`, `Kharkiv`),
            function(x) round(100*x/sum(x), 0))

df_lang_city <-
  lang_city_count_pct %>%
  left_join(lang_city_count, by = "category") %>%
  dplyr::select(-row_total.x) %>%
  dplyr::select(c(1,6,2,7, 3,8,4,9,5, 10)) %>%
  adorn_totals("row")

names(df_lang_city) <- c("category", rep(c('n','\\%'),times = 4), "Row Total")

kable(df_lang_city, format = "latex", booktabs = TRUE, digits = 2,
      caption="\\label{tbl:city_means_2} 
      Home language use by city.") %>%
  add_header_above(c(" ", "Kyiv" =2, "Kherson" =2, "Odesa" = 2, "Kharkiv" =2, "")) %>%
  row_spec(5, bold = TRUE) %>%
  cat(., file = "./tables/lang_city_pct.tex")


# LANGUAGE BY ETHNICITY
# generate Table B.5

lang_ethnicity_count <-
  as.data.frame.matrix(table(iat_data$home_language, iat_data$ethnicity)) %>% 
  rownames_to_column('language') %>%
  mutate(row_total = `Ukrainian only`+ `other`+ `Ukr and Rus` + `Russian only`) %>%
  arrange(desc(row_total))

lang_ethnicity_count_pct <-
  lang_ethnicity_count %>%
  mutate_at(vars(`Ukrainian only`, `other`, `Ukr and Rus`, `Russian only`),
            function(x) round(100*x/sum(x), 0))

df_lang_ethnicity <-
  lang_ethnicity_count_pct %>%
  left_join(lang_ethnicity_count, by = "language") %>%
  dplyr::select(-row_total.x) %>%
  dplyr::select(c(1,6,2,7, 3,8,4,9,5, 10)) %>%
  adorn_totals("row")

names(df_lang_ethnicity) <- c("language", rep(c('n','\\%'),times = 4), "Row Total")

kable(df_lang_ethnicity, format = "latex", booktabs = TRUE, digits = 2,
      caption="\\label{tbl:city_means_2} 
      Home language use by reported ethnic identity.") %>%
  add_header_above(c(" ", "Ukrainian eth." =2, "Other eth." =2, "Ukr \\&  Rus eth." = 2, "Russian eth." =2, "")) %>%
  row_spec(5, bold = TRUE) %>%
  cat(., file = "./tables/lang_ethnicity_pct.tex")



# unweighted scatter
# generates Figure 5
r <- as.character(round(cor(iat_data$IAT, iat_data$explicit), 2))

plot_text <-
  tibble(
    text = c("pro-Ukraine\ndissociation", "pro-Russia\ndissociation",
             str_c("r = ", r)),
    x = c(-1.5, 1.5, 1.75),
    y = c(4, -4, 4.25)
  )

ggplot(iat_data, aes(x = IAT, y = explicit)) +
  geom_point(position = position_jitter(height = 0.35), alpha = 0.5) +
  geom_smooth(method = "lm", se = FALSE, alpha = 0.5, color = "blue") +
  geom_text(data = plot_text, aes(x = x, y = y, label = text)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_vline(xintercept = 0, linetype = "dashed") +
  lims(x = c(-2, 2),
       y = c(-6.3, 6.3)) +
  labs(x = "implicit preference for Ukraine (d-score)",
       y = "explicit preference for Ukraine") +
  theme(panel.background = element_blank(),
        axis.text.y = element_text(angle = 90))

ggsave(filename = "plots/new_scatter.pdf",
       height = 6,
       width = 6)


# generate Figure F.6
# weighted scatter

wt_r <- as.character(round(wtd.cor(iat_data$IAT,
                                   iat_data$explicit,
                                   weight = iat_data$new_wt)[1], 2))

wt_plot_text <-
  tibble(
    text = c("pro-Ukraine\ndissociation",
             "pro-Russia\ndissociation",
             str_c("r = ", wt_r)),
    x = c(-1.5, 1.5, 1.75),
    y = c(4, -4, 4.25)
  )

wt_reg <- 
  lm(explicit ~ IAT, weights = new_wt, data = iat_data) %>%
  tidy()

wtd.cor(iat_data$IAT, iat_data$explicit, weight = iat_data$new_wt)

ggplot() +
  geom_point(data = iat_data, aes(x = IAT, size = new_wt, y = explicit),
             position = position_jitter(height = 0.25), alpha = 0.35) +
  geom_abline(intercept = wt_reg$estimate[1],
              slope = wt_reg$estimate[2],
              alpha = 0.5,
              color = "blue") +
  geom_text(data = wt_plot_text, aes(x = x, y = y, label = text)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_vline(xintercept = 0, linetype = "dashed") +
  lims(x = c(-2, 2),
       y = c(-6.3, 6.3)) +
  labs(x = "implicit bias",
       y = "explicit bias") +
  theme(panel.background = element_blank(),
        axis.text.y = element_text(angle = 90),
        legend.position = "none")

ggsave(filename = "plots/new_scatter_wt.pdf",
       height = 6,
       width = 6)

##
## regressions
##

iat_data <-
  iat_data %>%
  mutate(city = forcats::fct_relevel(city, "Kharkiv"))

# svy object for weighted regressions
iat_svy_obj <- svydesign(ids = ~ 0,
                         weights = ~new_wt,
                         data = iat_data %>%
                           filter(!is.na(new_wt)))

rus_imp <-
  IAT ~ ethnicity_Russian +
  city + unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3

rus_imp_eth4 <-
  IAT ~ ethnicity +
  city + unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3

rus_exp <-
  explicit ~ ethnicity_Russian +
  city + unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3 +
  IAT

rus_exp_eth4 <-
  explicit ~ ethnicity +
  city + unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3 +
  IAT

# interaction models Kyiv or East City by 4-category ethnicity

rus_imp_eth4_int <-
  IAT ~ ethnicity * city_2_cat +
  unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3

rus_exp_eth4_int <-
  explicit ~ ethnicity * city_2_cat +
  unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3 +
  IAT

# interaction models 2014 parl vote by 4-category ethnicity

rus_imp_eth4_party_int <-
  IAT ~ ethnicity * parl2014_3 +
  city_2_cat +unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3

rus_exp_eth4_party_int <-
  explicit ~ ethnicity * parl2014_3 +
  city_2_cat +unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3 +
  IAT

# interaction models 4 cities by 4-category ethnicity

rus_imp_eth4_int_city <-
  IAT ~ ethnicity * city +
  unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3

rus_exp_eth4_int_city <-
  explicit ~ ethnicity * city +
  unemployed + family_in_Russia + russian_speaking_d + female + age_sd + parl2014_3 +
  IAT

apr_bias_models <- list(rus_imp, rus_imp_eth4,
                        rus_exp, rus_exp_eth4, 
                        rus_imp_eth4_int, rus_exp_eth4_int,
                        rus_imp_eth4_party_int, rus_exp_eth4_party_int,
                        rus_imp_eth4_int_city, rus_exp_eth4_int_city)

# a function that drops variables from models
drop_var <- function(form, vars_to_drop = "- parl2014_3") {
  new_f <- update.formula(old = form,
                          new = str_c(as.character(form)[2],
                                      "~",
                                      as.character(form)[3],
                                      vars_to_drop))
  
  new_f
} 

apr_bias_models[[1]] <- drop_var(apr_bias_models[[1]])
apr_bias_models[[2]] <- drop_var(apr_bias_models[[2]])
apr_bias_models[[5]] <- drop_var(apr_bias_models[[5]])
apr_bias_models[[7]] <- drop_var(apr_bias_models[[7]], "- parl2014_3 - ethnicity:parl2014_3")
apr_bias_models[[9]] <- drop_var(apr_bias_models[[9]])

###

apr_bias_regs <- lapply(apr_bias_models, 
                        function(x) lm(x, data = iat_data))

apr_bias_robust_vcov <- lapply(apr_bias_regs, vcovHC, type = "HC")
apr_bias_robust_se <- lapply(apr_bias_robust_vcov,
                             function(x) sqrt(diag(x)))

##
## NEEDED FOR FINAL SEP 04 
##

int_note_new <- c("Robust SEs in parentheses. * p$< 0.05$. ** measured in standard deviation units.")

int_city4_rus_covar_labels_nodem_new <- c(
  "Russian (dummy)",
  "Eth. \\textit{(ref Ukrainian (only))}: Other",
  "\\quad : Ukr. and Rus.",
  "\\quad : Russian (only)",
  "City \\textit{(ref Kharkiv)} : Kyiv",
  "\\quad : Kherson",
  "\\quad : Odesa",
  # "Unemployed",
  #"Family in Russia"
  "Home lang. Russian (dummy)",
  # "Female",
  #"Age**",
  "2014 Vote \\textit{(ref Anti-Russia)} : Pro-Russia",
  "\\quad : Abstain",
  "IAT",
  "Other. eth. $\\times$ Kyiv",
  "Ukr. and Rus. $\\times$ Kyiv",
  "Russian (only). $\\times$ Kyiv",        
  "Other eth. $\\times$ City: Kherson",
  "Ukr. and Rus. $\\times$ Kherson",
  "Russian (only) $\\times$ Kherson",
  "Other eth. $\\times$ Odesa",            
  "Ukr. and Rus. $\\times$ Odesa",
  "Russian (only) $\\times$  Odesa",
  "Constant")


note_all_new <- 
  c("Robust SEs in parentheses. * p$< 0.05$.",
    "Demographics include  \\texttt{family in Russia} (negative in models 1, 3, 4, and 6), \\texttt{age}, and \\texttt{female}.")

tbl_file_name <- "./tables/rus_regressions_all_no_parl.tex"
bias_tex_label <- "tbl:reg_tbl_all_no_parl"

##
## NEEDED FOR FINAL SEP 04 
##

# generates Table E.7, Table F.9

DEMOVAR <- c("family.*|unemployed|female|age.*")
stargazer(
  apr_bias_regs[c(1:4, 9:10)],
  header = FALSE,
  label = bias_tex_label,
  table.placement = "H",
  se = apr_bias_robust_se[c(1:4, 9:10)],
  # type = "text",
  out = tbl_file_name,
  no.space = TRUE,
  # column.labels = rus_column_labels,
  dep.var.labels.include = TRUE,
  dep.var.caption = "Dependent variables: explicit attititudes or IAT $d$-score",
  dep.var.labels = c("IAT", "EXP", 
                     "IAT", "EXP"),
  column.sep.width = "-5pt",
  omit = DEMOVAR,
  omit.labels = rep("Demographics", length(DEMOVAR)),
  omit.yes.no = c("YES", "NO"),
  covariate.labels = int_city4_rus_covar_labels_nodem_new,
  notes = note_all_new,
  notes.align = "l",
  font.size = "scriptsize",
  star.cutoffs = c(.05, NA, NA),
  digits = 2,
  omit.stat = c("f"),
  notes.append = FALSE
)

####
# PREDICTING DISSOCIATION
####
# a function to update the formulas
update_pro_rus_dissoc <- function(form, dissoc_type) {
  new_f <- update.formula(old = form,
                          new = str_c(dissoc_type,
                                      as.character(form)[3],
                                      " + imp_pro_rus"))
  
  new_f
} 

dissoc_mods <- lapply(apr_bias_models[c(3, 4, 10)],
                      update_pro_rus_dissoc, dissoc_type = "dissoc ~ ")

apr_dissoc_regs <- lapply(dissoc_mods,
                          function(x) glm(x,
                                          family = binomial(link = "logit"),
                                          data = iat_data))

apr_dissoc_robust_vcov <- lapply(apr_dissoc_regs, vcovHC, type = "HC")
apr_dissoc_robust_se <- lapply(apr_dissoc_robust_vcov,
                               function(x) sqrt(diag(x)))


dissoc_labels_no_dem <- c(
  "Russian (dummy)",
  "Eth. \\textit{(ref Ukr (only))}: Other",
  "\\quad : Ukr. and Rus.",
  "\\quad : Russian (only)",
  "City \\textit{(ref Kharkiv)}: Kyiv",
  "\\quad : Kherson",
  "\\quad : Odesa",
  # "Unemployed",
  #"Family in Russia"
  "Home lang. Russian (dummy)",
  # "Female",
  #"Age**",
  "2014 Vote \\textit{(ref Anti-Russia)} : Pro-Russia",
  "\\quad : Abstain",
  "IAT",
  "Implicitly pro-Russia",
  "Other. eth. $\\times$ Kyiv",
  "Ukr. and Rus. $\\times$ Kyiv",
  "Russian (only). $\\times$ Kyiv",        
  "Other eth. $\\times$ City: Kherson",
  "Ukr. and Rus. $\\times$ Kherson",
  "Russian (only) $\\times$ Kherson",
  "Other eth. $\\times$ Odesa",            
  "Ukr. and Rus. $\\times$ Odesa",
  "Russian (only) $\\times$  Odesa",
  "Constant")

note_all_dissoc <- 
  c("Robust SEs in parentheses. * p$< 0.05$.",
    "Demographics include  \\texttt{family in Russia*}, \\texttt{age*} (positive in models 1, 2, and 3), and \\texttt{female}.")

dissoc_file_name <- "./tables/dissoc_regressions_all_no_parl.tex"
dissoc_tex_label <- "tbl:dissoc_tbl_all_no_parl"

# generate Table E.8

stargazer(
  apr_dissoc_regs,
  header = FALSE,
  table.placement = "H",
  se = apr_dissoc_robust_se,
  label = dissoc_tex_label,
  # type = "text",
  out = dissoc_file_name,
  no.space = TRUE,
  # column.labels = rus_column_labels,
  dep.var.labels.include = FALSE,
  dep.var.caption = "Dependent variables: dissociation (dummy variable)",
  # dep.var.labels = c("IAT", "EXP", 
  #                    "IAT", "EXP"),
  column.sep.width = "-5pt",
  omit = DEMOVAR,
  omit.labels = rep("Demographics", length(DEMOVAR)),
  omit.yes.no = c("YES", "NO"),
  covariate.labels = dissoc_labels_no_dem,
  notes = note_all_dissoc,
  notes.align = "l",
  font.size = "scriptsize",
  star.cutoffs = c(.05, NA, NA),
  digits = 2,
  omit.stat = c("f"),
  notes.append = FALSE
)